<div class="view-customize">
	<form>
		<div class="widget-list-picker widget-list-picker-horiz">
			<ul class="options">
				<li class="option {{if isDocumizeProvider "selected"}}" {{action "onDocumize"}} role="button" tabindex="0">
					<div class="text-header">Documize</div>
					<div class="text">{{localize 'auth_email_password'}}</div>
					{{#if isDocumizeProvider}}
						<i class="dicon {{constants.Icon.Tick}}" />
					{{/if}}
				</li>
				<li class="option {{if isKeycloakProvider "selected"}}" {{action "onKeycloak"}} role="button" tabindex="0">
					<div class="text-header">Keycloak</div>
					<div class="text">{{localize 'auth_connect_keycloak'}}</div>
					{{#if isKeycloakProvider}}
						<i class="dicon {{constants.Icon.Tick}}" />
					{{/if}}
				</li>
				<li class="option {{if isLDAPProvider "selected"}}" {{action "onLDAP"}} role="button" tabindex="0">
					<div class="text-header">LDAP</div>
					<div class="text">{{localize 'auth_connect_ldap'}}</div>
					{{#if isLDAPProvider}}
						<i class="dicon {{constants.Icon.Tick}}" />
					{{/if}}
				</li>
                <li class="option {{if isCASProvider "selected"}}" {{action "onCAS"}} role="button" tabindex="0">
                    <div class="text-header">CAS</div>
                    <div class="text">{{localize 'auth_connect_cas'}}</div>
                    {{#if isCASProvider}}
                        <i class="dicon {{constants.Icon.Tick}}" />
                    {{/if}}
                </li>
			</ul>
		</div>

		<Ui::UiSpacer @size="300" />

		{{#if isKeycloakProvider}}
			<div class="form-group">
				<label for="keycloak-url">{{localize 'auth_keycloak_url'}}</label>
				{{focus-input id="keycloak-url" type="text" value=keycloakConfig.url class=(if KeycloakUrlError "form-control is-invalid" "form-control")}}
				<small class="form-text text-muted">e.g. http://localhost:8888/auth</small>
			</div>
			<div class="form-group">
				<label for="keycloak-realm">{{localize 'auth_keycloak_realm'}}</label>
				{{input id="keycloak-realm" type="text" value=keycloakConfig.realm class=(if KeycloakRealmError "form-control is-invalid" "form-control")}}
				<small class="form-text text-muted">e.g. main</small>
			</div>
			<div class="form-group">
				<label for="keycloak-publicKey">{{localize 'auth_keycloak_pk'}}</label>
				{{textarea id="keycloak-publicKey" type="text" value=keycloakConfig.publicKey rows=7 class=(if KeycloakPublicKeyError "form-control is-invalid" "form-control")}}
				<small class="form-text text-muted">{{localize 'auth_keycloak_pk_explain'}}</small>
			</div>
			<div class="form-group">
				<label for="keycloak-clientId">{{localize 'auth_keycloak_oidc'}}</label>
				{{input id="keycloak-clientId" type="text" value=keycloakConfig.clientId class=(if KeycloakClientIdError "form-control is-invalid" "form-control")}}
				<small class="form-text text-muted">e.g. account</small>
			</div>
			<div class="form-group">
				<label for="keycloak-group">{{localize 'auth_keycloak_group'}}</label>
				{{input id="keycloak-group" type="text" value=keycloakConfig.group class="form-control"}}
				<small class="form-text text-muted">{{localize 'auth_keycloak_group_explain'}}</small>
			</div>
			<div class="form-group">
				<label for="keycloak-admin-user">{{localize 'auth_keycloak_username'}}</label>
				{{input id="keycloak-admin-user" type="text" value=keycloakConfig.adminUser class=(if KeycloakAdminUserError "form-control is-invalid" "form-control")}}
				<small class="form-text text-muted">{{localize 'auth_keycloak_username_explain'}}</small>
			</div>
			<div class="form-group">
				<label for="keycloak-admin-password">{{localize 'auth_keycloak_password'}}</label>
				{{input id="keycloak-admin-password" type="password" value=keycloakConfig.adminPassword class=(if KeycloakAdminPasswordError "form-control is-invalid" "form-control")}}
				<small class="form-text text-muted">{{localize 'auth_keycloak_password_explain'}}</small>
			</div>
			<div class="form-group">
				<label>{{localize 'auth_disable_logout'}}</label>
				{{x-toggle value=keycloakConfig.disableLogout size="medium" theme="light" onToggle=(action (mut keycloakConfig.disableLogout))}}
			</div>
			<div class="form-group">
				<label for="ldap-defaultPermissionAddSpace">{{localize 'auth_role_space'}}</label>
				{{x-toggle value=keycloakConfig.defaultPermissionAddSpace size="medium" theme="light" onToggle=(action (mut keycloakConfig.defaultPermissionAddSpace))}}
			</div>
		{{/if}}

		{{#if isLDAPProvider}}
			<div class="form-group">
				<label for="ldap-host">{{localize 'auth_ldap_server'}}</label>
				{{focus-input id="ldap-host" type="text" value=ldapConfig.serverHost class=(if ldapErrorServerHost "form-control is-invalid" "form-control")}}
				<small class="form-text text-muted">{{localize 'auth_ldap_server_explain'}}</small>
			</div>
			<div class="form-group">
				<label for="ldap-port">{{localize 'auth_ldap_port'}}</label>
				{{input id="ldap-port" type="number" value=ldapConfig.serverPort class=(if ldapErrorServerPort "form-control is-invalid" "form-control")}}
				<small class="form-text text-muted">{{localize 'auth_ldap_port_explain'}}</small>
			</div>
			<div class="form-group">
				<label for="ldap-encryption">{{localize 'encryption'}}</label>
				<select onchange={{action "onLDAPEncryption" value="target.value"}} class="form-control">
					<option value={{constants.AuthProvider.EncryptionTypeNone}} selected={{is-equal ldapConfig.encryptionType constants.AuthProvider.EncryptionTypeNone}}>
						{{constants.AuthProvider.EncryptionTypeNone}}
					</option>
					<option value={{constants.AuthProvider.EncryptionTypeStartTLS}} selected={{is-equal ldapConfig.encryptionType constants.AuthProvider.EncryptionTypeStartTLS}}>
						{{constants.AuthProvider.EncryptionTypeStartTLS}}
					</option>
				</select>
			</div>
			<div class="form-group">
				<label for="ldap-baseDN">{{localize 'auth_ldap_base'}}</label>
				{{input id="ldap-baseDN" type="text" value=ldapConfig.baseDN class="form-control"}}
				<small class="form-text text-muted">{{localize 'auth_ldap_base_explain'}}</small>
			</div>
			<div class="form-group">
				<label for="ldap-bindDN">{{localize 'auth_ldap_bind'}}</label>
				{{input id="ldap-bindDN" type="text" value=ldapConfig.bindDN class=(if ldapErrorBindDN "form-control is-invalid" "form-control")}}
				<small class="form-text text-muted">{{localize 'auth_ldap_bind_explain'}}</small>
			</div>
			<div class="form-group">
				<label for="ldap-bindPassword">{{localize 'auth_ldap_password'}}</label>
				{{input id="ldap-bindPassword" type="password" value=ldapConfig.bindPassword class=(if ldapErrorBindPassword "form-control is-invalid" "form-control")}}
				<small class="form-text text-muted">{{localize 'auth_ldap_bind_explain'}}</small>
			</div>
			<div class="form-group">
				<label for="ldap-userFilter">{{localize 'auth_ldap_filter_user'}}</label>
				{{input id="ldap-userFilter" type="text" value=ldapConfig.userFilter class=(if ldapErrorNoFilter "form-control is-invalid" "form-control")}}
				<small class="form-text text-muted">{{localize 'auth_ldap_filter_user_explain1'}}</small>
				<small class="form-text text-muted highlight">{{localize 'auth_ldap_filter_user_explain2'}}</small>
			</div>
			<div class="form-group">
				<label for="ldap-groupFilter">{{localize 'auth_ldap_filter_group'}}</label>
				{{input id="ldap-groupFilter" type="text" value=ldapConfig.groupFilter class=(if ldapErrorNoFilter "form-control is-invalid" "form-control")}}
				<small class="form-text text-muted">{{localize 'auth_ldap_filter_group_explain'}}</small>
			</div>

			<div class="form-group">
				<label for="ldap-attributeUserRDN">{{localize 'auth_ldap_rdn'}}</label>
				{{input id="ldap-attributeUserRDN" type="text" value=ldapConfig.attributeUserRDN class=(if ldapErrorAttributeUserRDN "form-control is-invalid" "form-control")}}
				<small class="form-text text-muted">{{localize 'auth_ldap_rdn_explain1'}}</small>
				<small class="form-text text-muted highlight">{{localize 'auth_ldap_rdn_explain2'}}</small>
			</div>
			<div class="form-group">
				<label for="ldap-attributeUserFirstname">{{localize 'auth_ldap_firstname'}}</label>
				{{input id="ldap-attributeUserFirstname" type="text" value=ldapConfig.attributeUserFirstname class=(if ldapErrorAttributeUserFirstname "form-control is-invalid" "form-control")}}
				<small class="form-text text-muted">{{localize 'auth_ldap_firstname_explain'}}</small>
			</div>
			<div class="form-group">
				<label for="ldap-attributeUserLastname">{{localize 'auth_ldap_lastname'}}</label>
				{{input id="ldap-attributeUserLastname" type="text" value=ldapConfig.attributeUserLastname class=(if ldapErrorAttributeUserLastname "form-control is-invalid" "form-control")}}
				<small class="form-text text-muted">{{localize 'auth_ldap_lastname_explain'}}</small>
			</div>
			<div class="form-group">
				<label for="ldap-attributeUserEmail">{{localize 'auth_ldap_email'}}</label>
				{{input id="ldap-attributeUserEmail" type="text" value=ldapConfig.attributeUserEmail class=(if ldapErrorAttributeUserEmail "form-control is-invalid" "form-control")}}
				<small class="form-text text-muted">{{localize 'auth_ldap_email_explain'}}</small>
			</div>
			<div class="form-group">
				<label for="ldap-attributeGroupMember">{{localize 'auth_ldap_group'}}</label>
				{{input id="ldap-attributeGroupMember" type="text" value=ldapConfig.attributeGroupMember class=(if ldapErrorAttributeGroupMember "form-control is-invalid" "form-control")}}
				<small class="form-text text-muted">{{localize 'auth_ldap_group_explain1'}}</small>
				<small class="form-text text-muted highlight">{{localize 'auth_ldap_group_explain2'}}</small>
			</div>
			<div class="form-group">
				<label for="ldap-disableLogout">{{localize 'auth_disable_logout'}}</label>
				{{x-toggle value=ldapConfig.disableLogout size="medium" theme="light" onToggle=(action (mut ldapConfig.disableLogout))}}
			</div>
			<div class="form-group">
				<label for="ldap-defaultPermissionAddSpace">{{localize 'auth_role_space'}}</label>
				{{x-toggle value=ldapConfig.defaultPermissionAddSpace size="medium" theme="light" onToggle=(action (mut ldapConfig.defaultPermissionAddSpace))}}
			</div>
			<div class="form-group">
				<label for="ldap-allowFormsAuth">{{localize 'auth_dual_login'}}</label>
				{{x-toggle value=ldapConfig.allowFormsAuth size="medium" theme="light" onToggle=(action (mut ldapConfig.allowFormsAuth))}}
				<small class="form-text text-muted">{{localize 'auth_dual_login_explain'}}</small>
			</div>
			{{ui/ui-button color=constants.Color.Yellow light=true label=(localize 'test') onClick=(action "onLDAPPreview")}}
			{{ui/ui-button-gap}}
		{{/if}}

		{{#if isCASProvider}}
            <div class="form-group">
                <label for="cas-url">{{localize 'auth_cas_url'}}</label>
                {{focus-input id="cas-url" type="text" value=casConfig.url class=(if casErrorUrl "form-control is-invalid" "form-control")}}
                <small class="form-text text-muted">{{localize 'auth_cas_url_explain'}}</small>
            </div>
            <div class="form-group">
                <label for="cas-redirect-url">{{localize 'auth_cas_back_url'}}</label>
                {{focus-input id="cas-redirect-url" type="text" value=casConfig.redirectUrl class=(if casErrorRedirectUrl "form-control is-invalid" "form-control")}}
                <small class="form-text text-muted">{{localize 'auth_cas_back_url_explain'}}</small>
            </div>
        {{/if}}

		{{ui/ui-button color=constants.Color.Green light=true icon=constants.Icon.Locked label=(localize 'activate') onClick=(action "onSave")}}
	</form>

	{{#if (gt keycloakFailure.length 0)}}
		<p class="admin-setting-failure my-3">{{localize 'error'}} :: {{keycloakFailure}}</p>
	{{/if}}
</div>

<div id="ldap-preview-modal" class="modal" tabindex="-1" role="dialog">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">{{localize 'auth_ldap_preview'}}</div>
			<div class="modal-body">
				{{#if ldapPreview.isError}}
					<p class="text-danger">{{ldapPreview.message}}</p>
				{{else}}
					<p class="text-success">{{localize 'auth_ldap_preview_result' ldapPreview.count}}</p>
					{{#each ldapPreview.users as |user|}}
						<p>{{user.firstname}} {{user.lastname}} ({{user.email}})</p>
					{{/each}}
				{{/if}}
			</div>
			<div class="modal-footer">
				{{ui/ui-button color=constants.Color.Gray light=true label=(localize 'cancel') dismiss=true}}
			</div>
		</div>
	</div>
</div>
